from Base import singleton
from twisted.test.test_amp import SWITCH_CLIENT_DATA
from Game import Room

@singleton
class lobby(object):
    Roomlst = []
    def __init__(self):
        self.maxusr = 500
        self.maxroom = 50
    def getStatus(self):
        if len(self.Roomlst) == 0:
            return None
        else:
            for r in (0, len(self.Roomlst)):
                if self.Roomlst[r].CanGetin():
                    return self.Roomlst[r]
            return None
    def createRoom(self):
        mRoom = Room()
        self.Roomlst.append(mRoom)
        return mRoom
    
    def EnterInRoom(self,ConnectionInfo,room):
        
        pass
@singleton
class EventHandler(object):
    def __init__(self,lobby=0):
        self.lobby = lobby
        pass
    def handlemsg(self,ConnectionInfo,msg):
        if msg.type == 'EnterRoom':
            _Room = self.lobby.getStatus()
            if _Room == None:
                mRoom = lobby.createRoom()
                lobby.EnterInRoom(ConnectionInfo, mRoom)
            else:
                lobby.EnterInRoom(ConnectionInfo, _Room)
    